import java.util.ArrayList;
import java.util.List;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-10-31
 * Time: 10:23
 */
public class JeepFuel {
    public static void main(String[] args) {
        int totalDistance = 1000; // 总距离
        int fuelCapacity = 500; // 油箱容量
        int fuelConsumption = 1; // 耗油率

        List<Integer> gasStations = findGasStations(totalDistance, fuelCapacity, fuelConsumption);

        System.out.println("在以下位置建立临时油库：");
        for (int i = 0; i < gasStations.size(); i++) {
            System.out.println("距离起点 " + gasStations.get(i) + "km 处，存储油量为 " + (fuelCapacity - i) + "L");
        }
    }
    private static List<Integer> findGasStations(int totalDistance, int fuelCapacity, int fuelConsumption) {
        List<Integer> gasStations = new ArrayList<>();
        int remainingDistance = totalDistance;
        while (remainingDistance > 0) {
            int requiredFuel = remainingDistance * fuelConsumption;
            if (requiredFuel <= fuelCapacity) {
                break; // 距离可以一次性到达终点，无需再建立油库
            } else {
                int gasStationDistance = (requiredFuel / fuelCapacity) * fuelCapacity;
                gasStations.add(gasStationDistance);
                remainingDistance -= gasStationDistance / fuelConsumption;
            }
        }
        return gasStations;
    }
}
